<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Model\Goods;
use DB;

class ShopController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // echo 111;
        // return view()
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        
        $goods = DB::table('shop')
                ->leftjoin('goods','shop.shop_id','=','goods.shop_id')
                ->where('shop.shop_id',$id)
                ->select('goods.*','shop.shop_logo','shop.store_name','shop.shop_id')
                ->paginate(4);   
        return view('home.shop_index')->with('goods',$goods);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *按价格排序
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function sortPrice($id){
        // $id = $request->id;
        // dd($id);
        $goods = DB::table('shop')
                ->leftjoin('goods','shop.shop_id','=','goods.shop_id')
                ->where('shop.shop_id',$id)
                ->orderBy('shop_price')
                ->select('goods.*','shop.store_name','shop.shop_logo')
                ->paginate(8); 
        // dd($goods);
                // return $goods;
                return view('home.shop_index')->with('goods',$goods);
    }
}
